package com.liyu.config;

import com.rabbitmq.client.BuiltinExchangeType;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 * @author 李誉
 * @date 2022-08-07 13:09
 * @description 优先队列
 */
@Slf4j
@Component
public class PriorityExchangeCommon {

    public static final String PRIORITY_EXCHANGE = "priority.exchange.hello";

    public static final String PRIORITY_QUEUE = "priority.queue.hello";

    public static final String PRIORITY_ROUTING_KEY = "priority.rk.hello";

    @Bean("priorityExchange")
    public Exchange priorityExchange() {
        return new ExchangeBuilder(PRIORITY_EXCHANGE, BuiltinExchangeType.DIRECT.getType()).build();
    }

    @Bean("priorityQueue")
    public Queue priorityQueue() {
        return QueueBuilder.durable(PRIORITY_QUEUE).maxPriority(10).build();
    }

    @Bean("priorityBinding")
    public Binding priorityBinding(Exchange priorityExchange, Queue priorityQueue) {
        return BindingBuilder.bind(priorityQueue).to(priorityExchange).with(PRIORITY_ROUTING_KEY).noargs();
    }
}
